import variables from '@/assets/styles/element-variables.scss'
import api from '@/api/systemManagement/baseSettings/index'
import theme from '@/utils/theme.js'
import store from '../index'
const baseSettings={
  namespaced: true,
  state: {
    logo:"",
    title:"",
    guide:"",
    theme: variables.theme,
  },
  mutations:{
    SET_LOGO: (state, logo) => {
      state.logo = logo;
    },
    SET_TITLE: (state, title) => {
      state.title = title;
    },
    SET_GUIDE: (state, guide) => {
      state.guide = guide;
    },
    SET_THEME: (state, theme) => {
      state.theme = theme;
    },
  },
  actions:{
    getSiteInfo({ state,commit }) {
      return new Promise((resolve, reject) => {
        api.getSiteInfo().then(res => {
          let info = eval("(" + res.data.value + ")")
          commit("SET_LOGO", info.logo);
          commit("SET_TITLE", info.name);
          commit("SET_GUIDE", info.guide);
          commit("SET_THEME", info.theme);
          resolve(info);
        }).catch(error => {
          //console.log("错误");
          reject(error);
        });
      })
    },
    setTheme({ commit },val){
      return new Promise((resolve, reject) => {
        theme.renderingTheme(val)
        commit("SET_THEME", val);
        resolve()
      })
    }
  }
}
export default baseSettings
